using System.Collections;
using AppodealAds.Unity.Api;
using Photon;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
using UnityStandardAssets.CrossPlatformInput;

public class PlayerSetup : Photon.MonoBehaviour
{
	public enum WeaponState
	{
		GravyGun = 0,
		Automate = 1,
		Pistol = 2,
		Sniper = 3,
		Bazooka = 4
	}

	public GameObject[] m_PlayerSkins;

	public FirstPersonCharacter c_FPSControl;

	public ThirdPersonCharacter c_ThirdControl;

	public EscapeMenu c_EscapeMenu;

	public GameObject m_CarCamera;

	private RCC_Camera s_CameraRCC;

	private GameObject m_objectCar;

	[HideInInspector]
	public Camera m_Camera;

	[HideInInspector]
	public Rigidbody m_Rigidbody;

	[HideInInspector]
	public CapsuleCollider m_Capsule;

	[HideInInspector]
	public PlayerShooter s_PlayerShooter;

	public GameObject AllWeapons;

	public int m_CurrentWeapon;

	public WeaponInHand[] m_WeaponInHand;

	[HideInInspector]
	public int currentSkinsPlayer;

	[HideInInspector]
	public PlayerHealth s_PlayerHealth;

	[HideInInspector]
	public RigidbodyFirstPersonController s_RigidibodyFPSController;

	[HideInInspector]
	public PlayerGravyGun s_PlayerGravyGun;

	[HideInInspector]
	public PlayerOthers s_PlayerOthers;

	[HideInInspector]
	public bool AWPZoom;

	public static bool m_AxisRegister;

	public Joystick m_Joystcik;

	public TouchPad m_TouchPad;

	[HideInInspector]
	public float currentSensivity = 1.5f;

	[HideInInspector]
	public Animator anim;

	public WeaponState s_WeaponState;

	public int MyAnimationsSerialiseInt;

	private bool m_ReadyToSpawn = true;

	public bool m_InCar;

	public bool m_ImDriver;

	private bool m_ReklamaReload = true;

	private int VechilesMask;

	private float bodyVertical;

	public GameObject Test;

	[HideInInspector]
	public bool admin;

	private void Awake()
	{
		s_RigidibodyFPSController = GetComponent<RigidbodyFirstPersonController>();
		s_PlayerHealth = GetComponent<PlayerHealth>();
		s_PlayerGravyGun = GetComponent<PlayerGravyGun>();
		m_Rigidbody = GetComponent<Rigidbody>();
		m_Capsule = GetComponent<CapsuleCollider>();
		s_PlayerOthers = GetComponent<PlayerOthers>();
		if (base.photonView.isMine || SavesAllFunctions.Local)
		{
			s_PlayerShooter = c_FPSControl.m_PlayerShooter;
			m_Camera = s_RigidibodyFPSController.cam;
			c_FPSControl.FirstPersonChar.SetActive(true);
			c_ThirdControl.ThirdPersonChar.SetActive(false);
			anim = c_FPSControl.anim_First;
			AllWeapons.transform.SetParent(c_FPSControl.HandFirst.transform);
			Cursor.lockState = CursorLockMode.Locked;
			Cursor.visible = false;
			m_CarCamera.transform.SetParent(null);
			s_CameraRCC = m_CarCamera.GetComponent<RCC_Camera>();
			if (!m_AxisRegister)
			{
				if (TouchPad.m_HorizontalVirtualAxis == null || TouchPad.m_VerticalVirtualAxis == null)
				{
					m_TouchPad.CreateVirtualAxes();
				}
				m_Joystcik.CreateVirtualAxes();
				m_AxisRegister = true;
			}
			if (!SavesAllFunctions.Local)
			{
				object[] instantiationData = base.photonView.instantiationData;
				admin = (bool)instantiationData[1];
			}
		}
		else if (!base.photonView.isMine)
		{
			m_Rigidbody.constraints = RigidbodyConstraints.FreezeAll;
			StartCoroutine("SerialiseTest");
			object[] instantiationData2 = base.photonView.instantiationData;
			int num = (int)instantiationData2[0];
			admin = (bool)instantiationData2[1];
			Debug.Log("CurrentSkinsPlayer : " + num);
			m_PlayerSkins[num].SetActive(true);
			c_ThirdControl.ThirdPersonChar = m_PlayerSkins[num].gameObject;
			c_ThirdControl.anim_Third = m_PlayerSkins[num].GetComponent<Animator>();
			c_ThirdControl.m_PlayerShooter = m_PlayerSkins[num].GetComponent<PlayerShooter>();
			c_ThirdControl.HandThird = getChildGameObject(m_PlayerSkins[num].gameObject, "Hand_Right_jnt");
			AllWeapons.transform.SetParent(c_ThirdControl.HandThird.transform);
			AllWeapons.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			GameObject childGameObject = getChildGameObject(m_PlayerSkins[num].gameObject, "Head_jnt");
			s_PlayerOthers.c_CanvasPlayer.TextPlayerName.transform.parent.SetParent(childGameObject.transform);
			c_ThirdControl.ThirdPersonChar.SetActive(true);
			c_FPSControl.FirstPersonChar.SetActive(false);
			s_PlayerShooter = c_ThirdControl.m_PlayerShooter;
			anim = c_ThirdControl.anim_Third;
		}
		AllWeapons.transform.localPosition = Vector3.zero;
		AllWeapons.transform.localScale = Vector3.one;
		VechilesMask = LayerMask.GetMask("Vehicle");
	}

	public GameObject getChildGameObject(GameObject fromGameObject, string withName)
	{
		Transform[] componentsInChildren = fromGameObject.transform.GetComponentsInChildren<Transform>(true);
		Transform[] array = componentsInChildren;
		foreach (Transform transform in array)
		{
			if (transform.gameObject.name == withName)
			{
				return transform.gameObject;
			}
		}
		return null;
	}

	private void Start()
	{
		ChangeWeapon(m_CurrentWeapon);
	}

	private void Update()
	{
		if (PhotonNetwork.room == null || PhotonNetwork.offlineMode || base.photonView.isMine)
		{
			PlayerUpdateFunct();
			WeaponUpdates();
			SetAnimation();
		}
	}

	private void PlayerUpdateFunct()
	{
		if (Input.GetKeyDown(KeyCode.E))
		{
			if (!m_InCar)
			{
				SitDownVechile();
			}
			else
			{
				StopCoroutine("IEOutWithCar");
				StartCoroutine("IEOutWithCar");
			}
		}
		if (CrossPlatformInputManager.GetButtonDown("AIM") && m_WeaponInHand[3].Weapon.activeSelf && !s_PlayerOthers.c_CanvasPlayer.ToolsMenuCanvas.activeSelf)
		{
			AWPZoom = !AWPZoom;
			c_FPSControl.changePricel.AWPZoom(AWPZoom);
		}
		if (s_PlayerGravyGun.m_delObject)
		{
			s_PlayerGravyGun.m_CanvasDelObj.fillAmount += Time.deltaTime / 0.75f;
		}
		else
		{
			s_PlayerGravyGun.m_CanvasDelObj.fillAmount = 0f;
		}
	}

	public void CarButtonSitDown()
	{
		if (!m_InCar)
		{
			SitDownVechile();
			return;
		}
		StopCoroutine("IEOutWithCar");
		StartCoroutine("IEOutWithCar");
	}

	public void SitDownVechile()
	{
		if (!s_PlayerHealth.m_Dead)
		{
			Ray ray = new Ray(m_Camera.transform.position, m_Camera.transform.forward);
			RaycastHit hitInfo;
			if (Physics.Raycast(ray, out hitInfo, 10f, VechilesMask) && !m_InCar)
			{
				StopCoroutine("IESitDownCar");
				StartCoroutine("IESitDownCar", hitInfo.transform.gameObject);
			}
		}
	}

	private IEnumerator IESitDownCar(GameObject hit)
	{
		yield return new WaitForSeconds(0.1f);
		ItemFunctions itemFunctions = hit.transform.gameObject.GetComponent<ItemFunctions>();
		if (!itemFunctions.m_Take && !itemFunctions.s_CarFunct.m_PlayerInCar && itemFunctions.s_CarFunct.playerInCar[0] == string.Empty)
		{
			Debug.Log("не мой ну сработал что мой ");
			if (PhotonNetwork.room != null && !PhotonNetwork.offlineMode)
			{
				PhotonView view = hit.transform.GetComponent<PhotonView>();
				if (!view.isMine)
				{
					view.RequestOwnership();
				}
				view.RPC("SitDownVechile", PhotonTargets.All, PhotonNetwork.playerName);
			}
			yield return new WaitForSeconds(0.1f);
			WhenSitDownInCar(hit.transform.gameObject, itemFunctions);
			itemFunctions.SitDownOrQuitInCar(true, true, base.gameObject, currentSkinsPlayer);
			s_PlayerGravyGun.DropObject(false);
			m_ImDriver = true;
		}
		else if (itemFunctions.PlayerInCarCurrent() < itemFunctions.s_CarFunct.m_maxPlayersInCar)
		{
			Debug.Log("SDADS");
			if (PhotonNetwork.room != null && !PhotonNetwork.offlineMode)
			{
				PhotonView view2 = hit.transform.GetComponent<PhotonView>();
				view2.RPC("SitDownVechile", PhotonTargets.All, PhotonNetwork.playerName);
			}
			yield return new WaitForSeconds(0.1f);
			WhenSitDownInCar(hit.transform.gameObject, itemFunctions);
			itemFunctions.SitDownOrQuitInCar(true, false, base.gameObject, currentSkinsPlayer);
			s_PlayerGravyGun.DropObject(false);
		}
	}

	private void WhenSitDownInCar(GameObject hit, ItemFunctions itemfunct)
	{
		m_InCar = true;
		m_Rigidbody.isKinematic = true;
		s_RigidibodyFPSController.cam.gameObject.SetActive(false);
		c_EscapeMenu.PlayerCanvas.SetActive(false);
		c_EscapeMenu.CanvasCarController.SetActive(true);
		m_objectCar = hit.transform.gameObject;
		s_CameraRCC.playerCar = m_objectCar.transform;
		s_CameraRCC.GetPlayerCar();
		m_CarCamera.SetActive(true);
		m_Capsule.enabled = false;
		if (!(m_objectCar.tag == "Car"))
		{
		}
	}

	public IEnumerator IEOutWithCar()
	{
		GameObject objVehicles = m_objectCar;
		yield return new WaitForSeconds(0.2f);
		m_InCar = false;
		m_CarCamera.SetActive(false);
		m_Rigidbody.isKinematic = false;
		s_RigidibodyFPSController.cam.gameObject.SetActive(true);
		c_EscapeMenu.PlayerCanvas.SetActive(true);
		c_EscapeMenu.CanvasCarController.SetActive(false);
		m_Capsule.enabled = true;
		base.gameObject.transform.eulerAngles = Vector3.up * m_objectCar.transform.eulerAngles.y;
		base.gameObject.transform.position = m_objectCar.transform.position - m_objectCar.transform.right * 3.25f + Vector3.up * 1.5f;
		ItemFunctions itemfuct = m_objectCar.GetComponent<ItemFunctions>();
		if (m_ImDriver)
		{
			itemfuct.SitDownOrQuitInCar(false, true, null, currentSkinsPlayer);
			m_ImDriver = false;
		}
		else
		{
			itemfuct.SitDownOrQuitInCar(false, false, null, currentSkinsPlayer);
		}
		if (!SavesAllFunctions.Local)
		{
			m_objectCar.GetComponent<PhotonView>().RPC("ExitVechile", PhotonTargets.All, PhotonNetwork.playerName);
		}
		anim.SetInteger("WeaponType_int", m_WeaponInHand[m_CurrentWeapon].number_Animation);
	}

	public void OutWithCar(GameObject car, Vector3 carvelocity)
	{
		GameObject objectCar = m_objectCar;
		m_InCar = false;
		m_CarCamera.SetActive(false);
		m_Rigidbody.isKinematic = false;
		s_RigidibodyFPSController.cam.gameObject.SetActive(true);
		c_EscapeMenu.CanvasCarController.SetActive(false);
		c_EscapeMenu.PlayerCanvas.SetActive(true);
		m_Capsule.enabled = true;
		base.gameObject.transform.eulerAngles = Vector3.up * car.transform.eulerAngles.y;
		base.gameObject.transform.position = new Vector3(car.transform.position.x - 2f, car.transform.position.y, car.transform.position.z);
		m_Rigidbody.velocity = carvelocity / 2f;
		m_ImDriver = false;
		anim.SetInteger("WeaponType_int", m_WeaponInHand[m_CurrentWeapon].number_Animation);
	}

	public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{
			stream.SendNext(MyAnimationsSerialiseInt);
			stream.SendNext(m_CurrentWeapon);
			stream.SendNext(bodyVertical);
			stream.SendNext(m_InCar);
			return;
		}
		int myAnimationsSerialiseInt = MyAnimationsSerialiseInt;
		MyAnimationsSerialiseInt = (int)stream.ReceiveNext();
		if (myAnimationsSerialiseInt != MyAnimationsSerialiseInt)
		{
			GetAnimation();
		}
		int currentWeapon = m_CurrentWeapon;
		m_CurrentWeapon = (int)stream.ReceiveNext();
		if (currentWeapon != m_CurrentWeapon)
		{
			WeaponSet(m_CurrentWeapon);
		}
		bodyVertical = (float)stream.ReceiveNext();
		if (c_ThirdControl.ThirdPersonChar.activeSelf)
		{
			anim.SetFloat("Body_Vertical_f", bodyVertical);
		}
		m_InCar = (bool)stream.ReceiveNext();
	}

	private IEnumerator SerialiseTest()
	{
		while (true)
		{
			yield return new WaitForSeconds(0.25f);
			if (m_InCar)
			{
				c_ThirdControl.ThirdPersonChar.SetActive(false);
				m_Capsule.enabled = false;
			}
			else if (!m_InCar)
			{
				m_Capsule.enabled = true;
				c_ThirdControl.ThirdPersonChar.SetActive(true);
			}
		}
	}

	private void WeaponUpdates()
	{
		if (!s_PlayerHealth.m_Dead)
		{
			switch (s_WeaponState)
			{
			case WeaponState.Automate:
			case WeaponState.Pistol:
			case WeaponState.Sniper:
			case WeaponState.Bazooka:
				s_PlayerShooter.UpdatePlayerShooter();
				break;
			case WeaponState.GravyGun:
				s_PlayerGravyGun.UpdateGravyGun();
				break;
			}
			if (Input.GetKey(KeyCode.Alpha1))
			{
				ChangeWeapon(0);
			}
			if (Input.GetKey(KeyCode.Alpha2))
			{
				ChangeWeapon(1);
			}
			if (Input.GetKey(KeyCode.Alpha3))
			{
				ChangeWeapon(2);
			}
			if (Input.GetKey(KeyCode.Alpha4))
			{
				ChangeWeapon(3);
			}
		}
	}

	public void ChangeWeapon(int Number)
	{
		if (Number == 0)
		{
			anim.SetBool("Shoot_b", false);
			s_WeaponState = WeaponState.GravyGun;
			WeaponSet(0);
		}
		if (Number == 1)
		{
			s_WeaponState = WeaponState.Automate;
			WeaponSet(1);
			s_PlayerGravyGun.DropObject(false);
		}
		if (Number == 2)
		{
			s_WeaponState = WeaponState.Pistol;
			WeaponSet(2);
			s_PlayerGravyGun.DropObject(false);
		}
		if (Number == 3)
		{
			s_WeaponState = WeaponState.Sniper;
			WeaponSet(3);
			s_PlayerGravyGun.DropObject(false);
		}
		if (Number == 4)
		{
			s_WeaponState = WeaponState.Bazooka;
			WeaponSet(4);
			s_PlayerGravyGun.DropObject(false);
		}
		s_PlayerShooter.ReloadWhenChangeWeapon();
		if (AWPZoom)
		{
			AWPZoom = !AWPZoom;
			c_FPSControl.changePricel.AWPZoom(AWPZoom);
		}
	}

	private void WeaponSet(int weaponNum)
	{
		m_CurrentWeapon = weaponNum;
		if (weaponNum > 0)
		{
			s_PlayerShooter.m_CurrentWP = weaponNum;
		}
		for (int i = 0; i < m_WeaponInHand.Length; i++)
		{
			m_WeaponInHand[i].Weapon.SetActive(false);
			if (weaponNum == i)
			{
				m_WeaponInHand[i].Weapon.SetActive(true);
			}
			if (PhotonNetwork.room == null || PhotonNetwork.offlineMode || base.photonView.isMine)
			{
				m_WeaponInHand[i].WeaponImageUI.enabled = false;
				if (weaponNum == i)
				{
					m_WeaponInHand[i].WeaponImageUI.enabled = true;
				}
			}
		}
		if (base.photonView.isMine || SavesAllFunctions.Local)
		{
			anim.SetInteger("WeaponType_int", m_WeaponInHand[m_CurrentWeapon].number_Animation);
			c_FPSControl.FirstPersonChar.transform.localRotation = Quaternion.Euler(0f, m_WeaponInHand[m_CurrentWeapon].WeaponRotate, 0f);
		}
		if (!base.photonView.isMine && c_ThirdControl.ThirdPersonChar.activeSelf)
		{
			anim.SetFloat("Head_Horizontal_f", m_WeaponInHand[m_CurrentWeapon].Head_Horizontal);
			anim.SetFloat("Body_Horizontal_f", m_WeaponInHand[m_CurrentWeapon].Body_Horizontal);
		}
	}

	private void SetAnimation()
	{
		if (!m_ImDriver && !m_InCar && (PhotonNetwork.room != null || !PhotonNetwork.offlineMode))
		{
			string empty = string.Empty;
			float @float = anim.GetFloat("Speed_f");
			empty = ((@float == 0f) ? (empty + 1) : ((@float == 0.3f) ? (empty + 2) : ((@float != 1f) ? (empty + 0) : (empty + 3))));
			bool @bool = anim.GetBool("Jump_b");
			if (@bool)
			{
				empty += 2;
			}
			else if (!@bool)
			{
				empty += 1;
			}
			switch (anim.GetInteger("DeathType_int"))
			{
			case 1:
				empty += 1;
				break;
			case 2:
				empty += 2;
				break;
			default:
				empty += 0;
				break;
			}
			bool bool2 = anim.GetBool("Death_b");
			if (bool2)
			{
				empty += 2;
			}
			else if (!bool2)
			{
				empty += 1;
			}
			int integer = anim.GetInteger("WeaponType_int");
			empty += integer;
			bool bool3 = anim.GetBool("Shoot_b");
			if (bool3)
			{
				empty += 2;
			}
			else if (!bool3)
			{
				empty += 1;
			}
			bool bool4 = anim.GetBool("Reload_b");
			if (bool4)
			{
				empty += 2;
			}
			else if (!bool4)
			{
				empty += 1;
			}
			MyAnimationsSerialiseInt = int.Parse(empty);
			if (s_RigidibodyFPSController.cam.transform.eulerAngles.x > 90f)
			{
				float num = (int)(50f - (s_RigidibodyFPSController.cam.transform.eulerAngles.x - 310f));
				float num2 = num / 5f;
				bodyVertical = num2;
			}
			else if (s_RigidibodyFPSController.cam.transform.eulerAngles.x <= 90f)
			{
				float num3 = (int)s_RigidibodyFPSController.cam.transform.eulerAngles.x;
				float num4 = num3 / 9f;
				bodyVertical = num4 * -1f;
			}
		}
	}

	private void GetAnimation()
	{
		string text = MyAnimationsSerialiseInt.ToString();
		if (!(anim == null) && !(text == string.Empty) && c_ThirdControl.ThirdPersonChar.activeSelf)
		{
			if (text[0] == '1')
			{
				anim.SetFloat("Speed_f", 0f);
			}
			else if (text[0] == '2')
			{
				anim.SetFloat("Speed_f", 0.3f);
			}
			else if (text[0] == '3')
			{
				anim.SetFloat("Speed_f", 1f);
			}
			if (text[1] == '1')
			{
				anim.SetBool("Jump_b", false);
			}
			else if (text[1] == '2')
			{
				anim.SetBool("Jump_b", true);
			}
			if (text[2] == '1')
			{
				anim.SetInteger("DeathType_int", 1);
			}
			else if (text[2] == '2')
			{
				anim.SetInteger("DeathType_int", 2);
			}
			else if (text[2] == '0')
			{
				anim.SetInteger("DeathType_int", 0);
			}
			if (text[3] == '1')
			{
				anim.SetBool("Death_b", false);
			}
			else if (text[3] == '2')
			{
				anim.SetBool("Death_b", true);
			}
			int num = text[4];
			if (text[4] == '0')
			{
				anim.SetInteger("WeaponType_int", 0);
			}
			else if (text[4] == '1')
			{
				anim.SetInteger("WeaponType_int", 1);
			}
			else if (text[4] == '2')
			{
				anim.SetInteger("WeaponType_int", 2);
			}
			else if (text[4] == '3')
			{
				anim.SetInteger("WeaponType_int", 3);
			}
			else if (text[4] == '4')
			{
				anim.SetInteger("WeaponType_int", 4);
			}
			else if (text[4] == '5')
			{
				anim.SetInteger("WeaponType_int", 5);
			}
			else if (text[4] == '6')
			{
				anim.SetInteger("WeaponType_int", 6);
			}
			else if (text[4] == '7')
			{
				anim.SetInteger("WeaponType_int", 7);
			}
			else if (text[4] == '8')
			{
				anim.SetInteger("WeaponType_int", 8);
			}
			else if (text[4] == '9')
			{
				anim.SetInteger("WeaponType_int", 9);
			}
			if (text[5] == '1')
			{
				anim.SetBool("Shoot_b", false);
			}
			else if (text[5] == '2')
			{
				anim.SetBool("Shoot_b", true);
			}
			if (text[6] == '1')
			{
				anim.SetBool("Reload_b", false);
			}
			else if (text[6] == '2')
			{
				anim.SetBool("Reload_b", true);
			}
			MyAnimationsSerialiseInt = int.Parse(text);
		}
	}

	public void SpawnObject(string nameObject)
	{
		if (nameObject[0] == 'P' && nameObject[1] == 'r' && nameObject[2] == 'o' && nameObject[3] == 'p' && nameObject[4] == 's')
		{
			ManagerSpawnObject(nameObject);
		}
		if (nameObject[0] == 'C' && nameObject[1] == 'a' && nameObject[2] == 'r')
		{
			ManagerSpawnVechiles(nameObject);
		}
	}

	public void ManagerSpawnVechiles(string nameOjbect)
	{
		if (PlayerPrefs.HasKey(nameOjbect))
		{
			if (PlayerPrefs.GetInt(nameOjbect) != 1)
			{
				StopCoroutine("DontHaveCar");
				StartCoroutine("DontHaveCar");
			}
			else if (PhotonNetwork.room != null && !PhotonNetwork.offlineMode)
			{
				int num = 0;
				for (int i = 0; i < Manager.Instance.m_MyVechiles.Length; i++)
				{
					if (!(Manager.Instance.m_MyVechiles[i] == null))
					{
						continue;
					}
					if (!m_InCar)
					{
						Ray ray = new Ray(m_Camera.transform.position, m_Camera.transform.forward);
						RaycastHit hitInfo;
						if (Physics.Raycast(ray, out hitInfo, 40f))
						{
							Manager.Instance.m_MyVechiles[i] = PhotonNetwork.Instantiate(nameOjbect, hitInfo.point + Vector3.up * 3f, base.transform.rotation, 0, null);
						}
					}
					break;
				}
			}
			else if (!m_InCar)
			{
				Ray ray2 = new Ray(m_Camera.transform.position, m_Camera.transform.forward);
				RaycastHit hitInfo2;
				if (Physics.Raycast(ray2, out hitInfo2, 40f))
				{
					GameObject gameObject = Object.Instantiate(Resources.Load<GameObject>(nameOjbect), hitInfo2.point + Vector3.up * 3f, base.transform.rotation) as GameObject;
				}
			}
		}
		else
		{
			StopCoroutine("DontHaveCar");
			StartCoroutine("DontHaveCar");
		}
	}

	private IEnumerator DontHaveCar()
	{
		s_PlayerOthers.c_CanvasPlayer.YouDontHaveCar.SetActive(true);
		yield return new WaitForSeconds(1.5f);
		s_PlayerOthers.c_CanvasPlayer.YouDontHaveCar.SetActive(false);
	}

	private IEnumerator ReadyToSpawnObject()
	{
		yield return new WaitForSeconds(0.6f);
		m_ReadyToSpawn = true;
	}

	public void ManagerSpawnObject(string nameObject)
	{
		if (m_InCar)
		{
			return;
		}
		Ray ray = new Ray(m_Camera.transform.position, m_Camera.transform.forward);
		RaycastHit hitInfo;
		if (!Physics.Raycast(ray, out hitInfo, 40f))
		{
			return;
		}
		if (PhotonNetwork.room != null && !PhotonNetwork.offlineMode)
		{
			if (PhotonNetwork.isMasterClient)
			{
				SpawnObject(nameObject, hitInfo.point + Vector3.up * 3f);
				m_ReadyToSpawn = false;
				StartCoroutine(ReadyToSpawnObject());
			}
			else
			{
				base.photonView.RPC("MessageToSpawnObject", PhotonTargets.MasterClient, nameObject, hitInfo.point + Vector3.up * 3f);
				m_ReadyToSpawn = false;
				StartCoroutine(ReadyToSpawnObject());
			}
		}
		else
		{
			SpawnObject(nameObject, hitInfo.point + Vector3.up * 3f);
		}
	}

	[PunRPC]
	private void MessageToSpawnObject(string nameObject, Vector3 objectPos)
	{
		SpawnObject(nameObject, objectPos);
	}

	private void SpawnObject(string nameObject, Vector3 objectPos)
	{
		if (PhotonNetwork.room != null && !PhotonNetwork.offlineMode)
		{
			GameObject gameObject = PhotonNetwork.InstantiateSceneObject(nameObject, objectPos, base.transform.rotation, 0, null);
			RoomPropertyFunction.AddItemScore();
		}
		else
		{
			Object.Instantiate(Resources.Load<GameObject>(nameObject), objectPos, base.transform.rotation);
		}
	}

	public void RespawnPlayer()
	{
		Cursor.lockState = CursorLockMode.Locked;
		Cursor.visible = false;
		c_EscapeMenu.CanvasRestart.SetActive(false);
		c_EscapeMenu.PlayerCanvas.SetActive(true);
		s_PlayerOthers.c_CanvasPlayer.PalyerButtonPanels.SetActive(true);
		s_PlayerOthers.c_CanvasPlayer.PlayerWeaponPanelsCanvas.SetActive(true);
		anim.SetBool("Death_b", false);
		anim.SetInteger("DeathType_int", 0);
		m_Rigidbody.isKinematic = false;
		ActivateControl();
		s_PlayerHealth.m_currentHP = s_PlayerHealth.m_maxHP;
		s_PlayerHealth.m_Dead = false;
		base.gameObject.transform.position = Manager.Instance.GetRandomPlayerPosition();
		for (int i = 0; i < s_PlayerShooter.m_Weapon.Length; i++)
		{
			s_PlayerShooter.m_Weapon[i].boletsСurent = s_PlayerShooter.m_Weapon[i].boletsMax;
		}
		m_Rigidbody.drag = 0f;
		m_Capsule.enabled = true;
		WeaponSet(m_CurrentWeapon);
		s_RigidibodyFPSController.advancedSettings.groundCheckDistance = 0.1f;
	}

	public void ActivateControl()
	{
		s_RigidibodyFPSController.enabled = true;
		s_PlayerHealth.m_CameraDead.enabled = false;
		m_Camera.enabled = true;
	}

	public void Dead()
	{
		anim.SetBool("Shoot_b", false);
		anim.SetBool("Reload_b", false);
		s_PlayerGravyGun.DropObject(false);
		c_EscapeMenu.PlayerCanvas.SetActive(false);
		s_PlayerOthers.c_CanvasPlayer.ToolsMenuCanvas.SetActive(false);
		StartCoroutine(RefreshPlayer());
	}

	public IEnumerator RefreshPlayer()
	{
		yield return new WaitForSeconds(3f);
		c_EscapeMenu.CanvasRestart.SetActive(true);
		Cursor.lockState = CursorLockMode.Confined;
		Cursor.visible = true;
		yield return new WaitForSeconds(0.2f);
		if (!m_ReklamaReload)
		{
			yield break;
		}
		Debug.Log("REKLAMA");
		int i = Random.Range(1, 100);
		if (i < 10)
		{
			if (Appodeal.isLoaded(2))
			{
				Appodeal.show(2);
				m_ReklamaReload = false;
				StartCoroutine(RefreshReklama());
			}
		}
		else if (Appodeal.isLoaded(1))
		{
			Appodeal.show(1);
			m_ReklamaReload = false;
			StartCoroutine(RefreshReklama());
		}
	}

	private IEnumerator RefreshReklama()
	{
		yield return new WaitForSeconds(25f);
		m_ReklamaReload = true;
	}
}
